package com.twu.biblioteca.users;

public class User {

    private final String name;
    private final String email;
    private final String phoneNumber;
    private final String libraryNumber;
    private final String password;

    public User(String name, String email, String phoneNumber, String libraryNumber, String password) {
        this.name = name;
        this.email = email;
        this.phoneNumber = phoneNumber;
        this.libraryNumber = libraryNumber;
        this.password = password;
    }

    public boolean authenticate(String password) {
        return (this.password.equals(password));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (!email.equals(user.email)) return false;
        if (!libraryNumber.equals(user.libraryNumber)) return false;
        if (!name.equals(user.name)) return false;
        if (!password.equals(user.password)) return false;
        if (!phoneNumber.equals(user.phoneNumber)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + email.hashCode();
        result = 31 * result + phoneNumber.hashCode();
        result = 31 * result + libraryNumber.hashCode();
        result = 31 * result + password.hashCode();
        return result;
    }

    @Override
    public String toString(){
        return ("Name: " + this.name + "\nEmail: " + this.email + "\nPhone Number: " + this.phoneNumber);
    }

}
